﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using StudyCompanion.Commons.Result;

namespace StudyCompanion.Commons.Filters;

public class GlobalExceptionsFilter : IExceptionFilter
{
    /// <summary>
    /// </summary>
    /// <param name="context"></param>
    public void OnException(ExceptionContext context)
    {
        context.Result = new ObjectResult(new CommonResult { Code = 400, Message = context.Exception.Message });
        context.ExceptionHandled = true;
    }
}